﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.IO;
using Microsoft.Win32;
using Pay_My_Client.LocalEntity;

using  Pay_My_Interface.Entity;

namespace Pay_My_Client.Interface.UserGestion
{
    /// <summary>
    /// Logique d'interaction pour Window1.xaml
    /// </summary>
    /// 


   public partial class AjoutUtilisateurWindow : Window
    {

       
      

        IUser utilisateur;
        IUser _user;

        public AjoutUtilisateurWindow()
        {
            InitializeComponent();
            utilisateur = new LocalEntity.User();
            _user = null;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Stream myStream = null;
            OpenFileDialog openPictureDialog1 = new OpenFileDialog();

            openPictureDialog1.Title = "Choisir une image";
            openPictureDialog1.Filter = "jpeg files (*.jpeg)|*.jpeg| png files (*.png) |*.png| jpg files (*.jpg) |*.jpg| gif files (*.gif) |*.gif";
            openPictureDialog1.CheckFileExists = true;
            openPictureDialog1.CheckPathExists = true;

            Nullable<bool> ret;
            ret = openPictureDialog1.ShowDialog(this);
            if (ret == true)
            {
                if ((myStream = openPictureDialog1.OpenFile()) != null)
                {
                    System.Drawing.Image img = System.Drawing.Image.FromStream(myStream);
                    utilisateur.photo = img;

                    System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(img);
                    IntPtr hBitmap = bmp.GetHbitmap();
                    System.Windows.Media.ImageSource WpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                    image1.Source = WpfBitmap;
                }
            }
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            string erreur = null;

            if (this.last.Text == "")
                erreur = "Le champ Nom doit être rempli";
            else if (this.first.Text == "")
                erreur = "Le champ Prénom doit être rempli";
            else if (erreur != null)
                MessageBox.Show(erreur, "Erreur...", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
            else
            {
                utilisateur.LastName = this.last.Text;
                utilisateur.FirstName = this.first.Text;
                utilisateur.solde = 0;
                utilisateur.InscDate = new DateTime();
                utilisateur.IsAdmin = false;
                utilisateur.IsStaff = false;
                _user = utilisateur;
                this.Close();
            }
        }


        public new IUser ShowDialog()
        {
            base.ShowDialog();
            return _user;
        }

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            BoutonCarte.Content = "En attente ...";
            utilisateur.code = "######";
            BoutonCarte.Content = "Numéro : ###### ";
        }

        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
